﻿// JScript 文件
CreateGoogle(160,600,null,null,null,null,null,null,null,null);
//Browse
var gPageIndex = 1;
//Browse 大图标页
var picPageIndex = 1;
//详细排列或图片排列（1详细，0图片）
var DetailedOrPic = 1;
//当前搜索类型(1：Browse，2：Search 会员号、email、昵称名)
var searchType = 1;
//会员号、email、昵称名搜索页
var gPageIndexNEM = 1;
//Search 大图标页
var picPageIndexNEM = 1;
//会员号、email、昵称名搜索值
var searchVal="";
//是否改变了搜索记录
var IsChangeSCount=-1;
function pageLoad(sender, args) 
{
    if(typeof(userPage) != "undefined")
    {
        if(DetailedOrPic==1)
        {
            RendPageNavigator(userPage,"divPage","GetPageMembers");
        }
        else if(DetailedOrPic==0)
        {
            RendPageNavigator(userPage,"divPage","GetPageMPic");
        }            
    } 
}
//显示Browse或Search
function showBorS(val)
{    
    if(val==1){        
        $get("Filter").style.display="";
        $get("Filter2").style.display="none";
        $get("spanQuesType1").className="first selATags";
        $get("spanQuesType2").className="";
    }
    else if(val==2){
        $get("Filter").style.display="none";
        $get("Filter2").style.display="";
        $get("spanQuesType1").className="first";
        $get("spanQuesType2").className="selATags";
    }
}
//Search搜索
function SearchDocs()
{
    searchType = 2;
    showProgressBar(true);    
    searchVal = $get("textSear2").value;     
    if(searchVal==""||searchVal==null || searchVal==gTypeD)
    {
        $get("textSear2").value=gTypeD;
        showProgressBar(false);
        return;
    }
    else if(searchVal==cityVal)
    {
        showProgressBar(false);
        return;
    }
    IsChangeSCount=1;
    IntiDMembersNEM(searchVal,1);
}
//获取会员号、email、昵称名搜索数据
function IntiDMembersNEM(searchV,pageIndex)
{
    if(DetailedOrPic==1)
    {
        WebServices.User.Contacts.GetSMembers(searchV,Memberno,pageIndex,20,onsuccMemberNEM);
    }
    else if(DetailedOrPic==0)
    {
        WebServices.User.Contacts.GetSMembers(searchV,Memberno,pageIndex,30,onsuccMPicNEM);
    } 
}
//初始数据(Search搜索)
function onsuccMemberNEM(result)
{
    if(IsChangeSCount==1)
    {
        RendMemberCount(result[1].RecordCount,"SearCount");
    }   
    RendMemberList(result[0],"memberList");
    RendPageNavigator(result[1],"divPage","GetPageMemberNEM");   
    showProgressBar(false);
}
//获取页面数据（页索引）
function GetPageMemberNEM(pageIndex)
{
    showProgressBar(true);
    gPageIndexNEM = pageIndex;
    IntiDMembersNEM(searchVal,gPageIndexNEM);
}
//Browse搜索
function SearBrowseDocs()
{ 
    searchType=1; 
    learnL = "";
    speakL = "";    
    var age=$get("selAge").value;
    var arr=age.split("-");
    minAgeVal=arr[0].toString();
    maxAgeVal=arr[1].toString();
    showProgressBar(true);    
    currentSearVal($get("selLearnL").value,$get("selSpeakL").value,$get("selCountry").value,maxAgeVal,minAgeVal,$get("selGender").value,$get("textSearCity").value,$get("iconCheck").checked,false,1);//, $get("isChatNowCheck").checked
    if($get("defaultSearquery").checked)
    {
        SetCookie();
    }   
}
//当前搜索值
function currentSearVal(learn,speak,nation,maxAge,minAge,gender,city,isAvatar,isChatNow,pageIndex)
{
    IsChangeSCount=1;
    if(learnL != ""||speakL != "")
    {
        InitDataMembers(learnL,speakL,"","200","0","","",false,false,pageIndex);
    }
    else{
        learnVal=learn;
        speakVal=speak;
        nationVal=nation;
        maxAgeVal=maxAge;
        minAgeVal=minAge;
        genderVal=gender;
        cityVal=city;
        isAvatarVal=isAvatar;
        isChatNowVal = isChatNow;
        InitDataMembers(learnVal,speakVal,nationVal,maxAgeVal,minAgeVal,genderVal,cityVal,isAvatarVal,isChatNowVal,pageIndex);
    }
}
//初始数据（详细排列数据）
function onsuccMembers(result)
{
    if(IsChangeSCount==1)
    {
        RendMemberCount(result[1].RecordCount,"SearCount");
    } 
    RendMemberList(result[0],"memberList");
    RendPageNavigator(result[1],"divPage","GetPageMembers");   
    showProgressBar(false);
}

//获取数据（页索引）
function InitDataMembers(learn,speak,nation,maxAge,minAge,gender,city,isAvatar,isChatNowVal,pageIndex)
{ 
    //GetMembers(string learnL, string speakL, string nation, string maxAge, string minAge, string gender, string city, bool isAvatar, bool isChatNow, string nnMnMe, string memberno, int pageIndex, int pageSize)
    if(DetailedOrPic==1)
    {
        WebServices.User.Contacts.GetMembers(learn,speak,nation,maxAge,minAge,gender,city,isAvatar,isChatNowVal,Memberno,pageIndex,20,onsuccMembers);
    }
    else if(DetailedOrPic==0)
    {
        WebServices.User.Contacts.GetMembers(learn,speak,nation,maxAge,minAge,gender,city,isAvatar,isChatNowVal,Memberno,pageIndex,30,onsuccMPic);
    }    
}
//获取页面数据（页索引）
function GetPageMembers(pageIndex)
{
    showProgressBar(true);
    gPageIndex = pageIndex;
    InitDataMembers(learnVal,speakVal,nationVal,maxAgeVal,minAgeVal,genderVal,cityVal,isAvatarVal,isChatNowVal,gPageIndex);
}
//替换搜索值数量
function RendMemberCount(count,divID)
{
    var domDiv =$get(divID);
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }         
        if($get("SearCountItem")==null) return;        
        var item= $get("SearCountItem").innerHTML;
        var tmp = item.replace(/\$SearchCount\$/gi,count==0?gNoCount:(count>499?gCounts5:gCounts.replace("{0}",count)));
        domDiv.innerHTML = tmp;
    }
}
function RendMemberList(list,divID)
{
    var domDiv =$get(divID);
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }         
        if($get("MemberTemple")==null) return;        
        var item= $get("MemberTemple").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        var listLength = list.length;
        for (var index = 0; index < listLength; index++) 
        {
            var obj = list[index];                     
            var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.Avatar==""?"/Images/No_pic.gif":obj.Avatar)+"\"/>").replace(/\$MemberNo\$/gi,obj.MemberNo).replace(/\$NickName\$/gi,obj.Nickname);
            tmp = tmp.replace(/\$Nationality\$/gi,GetLanguageLabel("jselCountry",obj.Nationality)).replace(/\$Country\$/gi,GetLanguageLabel("selCountry",obj.Country)).replace(/\$City\$/gi,obj.City!=""? obj.City+", ":"");            
            tmp = tmp.replace(/\$MotherTongue\$/gi,GetLanguageLabel("selLang",obj.MotherTongue)+"<img src=\"/Images/Level5.gif\"/>");
            tmp = tmp.replace(/\$TargetLanguage\$/gi,GetLanguageLabel("selLang",obj.TargetLanguage)+"<img src=\"/Images/Level"+obj.TargetLanguageLevel+".gif\"/>");
            tmp = tmp.replace(/\$Age\$/gi,obj.Age == "" ? "" : obj.Age).replace(/\$C0003\$/gi,C0003).replace(/\$C0009\$/gi,C0009).replace(/\$C0005\$/gi,C0005).replace(/\$C0007\$/gi,C0007);
            tmp = tmp.replace(/\$MotherTongue2\$/gi,obj.MotherTongue2 != "" ? ", "+GetLanguageLabel("selLang",obj.MotherTongue2)+"<img src=\"/Images/Level"+obj.MotherTongue2Level+".gif\"/>" : "");
            tmp = tmp.replace(/\$MotherTongue3\$/gi,obj.MotherTongue3 != "" ? ", "+GetLanguageLabel("selLang",obj.MotherTongue3)+"<img src=\"/Images/Level"+obj.MotherTongue3Level+".gif\"/>" : "");
            tmp = tmp.replace(/\$MotherTongue4\$/gi,obj.MotherTongue4 != "" ? ", "+GetLanguageLabel("selLang",obj.MotherTongue4)+"<img src=\"/Images/Level"+obj.MotherTongue4Level+".gif\"/>" : "");
            tmp = tmp.replace(/\$TargetLanguage2\$/gi,obj.TargetLanguage2 != "" ? ", "+GetLanguageLabel("selLang",obj.TargetLanguage2)+"<img src=\"/Images/Level"+obj.TargetLanguage2Level+".gif\"/>" : "");
            tmp = tmp.replace(/\$TargetLanguage3\$/gi,obj.TargetLanguage3 != "" ? ", "+GetLanguageLabel("selLang",obj.TargetLanguage3)+"<img src=\"/Images/Level"+obj.TargetLanguage3Level+".gif\"/>" : "");
            tmp = tmp.replace(/\$TargetLanguage4\$/gi,obj.TargetLanguage4 != "" ? ", "+GetLanguageLabel("selLang",obj.TargetLanguage4)+"<img src=\"/Images/Level"+obj.TargetLanguage4Level+".gif\"/>" : "");
            tmp = tmp.replace(/\$Avatar_title\$/gi,obj.Avatar_title == "" ? "" : "<div class='thoughtbox'><div><div><div><div>"+obj.Avatar_title+"</div></div></div></div></div>");
            tmp = tmp.replace(/\$Online\$/gi,obj.Online==true?gOnlineN:"");
            if(obj.Gender=="1")
            {
                tmp = tmp.replace(/\$Gender\$/gi,gMale);
            }
            else if(obj.Gender=="0")
            {
                tmp = tmp.replace(/\$Gender\$/gi,gFemale);
            }
            else
            {
                tmp = tmp.replace(/\$Gender\$/gi,"");
            }            
            listBuilder.append(tmp);
        }
        var sTemp = listBuilder.toString();
         domDiv.innerHTML = sTemp;           
    }
}

//(1详细列表排列，0图标列表排列)
function PicRange(type)
{
    showProgressBar(true);
    DetailedOrPic=type;
    if(searchType==1)
    {
        if(DetailedOrPic==1)
        {
            InitDataMembers(learnVal,speakVal,nationVal,maxAgeVal,minAgeVal,genderVal,cityVal,isAvatarVal,isChatNowVal,gPageIndex);
        }
        else if(DetailedOrPic==0)
        {
            InitDataMembers(learnVal,speakVal,nationVal,maxAgeVal,minAgeVal,genderVal,cityVal,isAvatarVal,isChatNowVal,picPageIndex);            
        }        
    }
    else if(searchType==2)
    {
        if(DetailedOrPic==1)
        {
            IntiDMembersNEM(searchVal,gPageIndexNEM);
        }
        else if(DetailedOrPic==0)
        {
            IntiDMembersNEM(searchVal,picPageIndexNEM);          
        }          
    }
}
//初始数据图标列表search
function onsuccMPicNEM(result)
{
    if(IsChangeSCount==1)
    {
        RendMemberCount(result[1].RecordCount,"SearCount");
    } 
    RendMListPic(result[0],"memberList");
    RendPageNavigator(result[1],"divPage","GetPageMemberNEM");   
    showProgressBar(false);
}
//获取页面数据（页索引）search
function GetPageMPicNEM(pageIndex)
{
    showProgressBar(true);
    picPageIndexNEM = pageIndex;
    IntiDMembersNEM(searchVal,picPageIndexNEM);
}

//初始数据 Browse
function onsuccMPic(result)
{
    if(IsChangeSCount==1)
    {
        RendMemberCount(result[1].RecordCount,"SearCount");
    } 
    RendMListPic(result[0],"memberList");
    RendPageNavigator(result[1],"divPage","GetPageMPic");   
    showProgressBar(false);
}
//获取页面数据（页索引）Browse
function GetPageMPic(pageIndex)
{
    showProgressBar(true);
    picPageIndex = pageIndex;
    InitDataMembers(learnVal,speakVal,nationVal,maxAgeVal,minAgeVal,genderVal,cityVal,isAvatarVal,isChatNowVal,picPageIndex);
}
//横向图标列表排列替换
function RendMListPic(list,divID)
{
    var domDiv =$get(divID);
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }         
        if($get("MemberTemple2")==null) return;        
        var item= $get("MemberTemple2").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        for (var index = 0; index < list.length; index++) 
        {              
            var obj = list[index];                     
            var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.Avatar==""?"/Images/No_pic.gif":obj.Avatar)+"\"/>").replace(/\$MemberNo\$/gi,obj.MemberNo).replace(/\$NickName\$/gi,obj.Nickname);            
            listBuilder.append(tmp);
        }
        var sTemp = listBuilder.toString();
         domDiv.innerHTML = sTemp;           
    }
}
//用户语言交换或学习伙伴（1语言交换，0学习伙伴）
function LanExchangesOrBuddies(type)
{   
    if(!Memberno||Memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }
    gPageIndex=1;
    picPageIndex=1;
    maxAgeVal="200";
    nationVal="";
    minAgeVal="0";
    genderVal="";
    cityVal="";
    isAvatarVal=false;
    isChatNowVal = false;
    showProgressBar(true);    
    if(type==1)
    {
        learnVal=memberSpeak;
        speakVal=memberLearn;
        InitDataMembers(memberSpeak,memberLearn,nationVal,maxAgeVal,minAgeVal,genderVal,cityVal,isAvatarVal,isChatNowVal,gPageIndex);
    }
    else if(type==0)
    {
       learnVal=memberLearn;
       speakVal=memberSpeak;
       InitDataMembers(memberLearn,memberSpeak,nationVal,maxAgeVal,minAgeVal,genderVal,cityVal,isAvatarVal,isChatNowVal,gPageIndex); 
    }
}
//设定Cookie值
function SetCookie()
{
    if(!Memberno||Memberno=="")
    {
        return;
    }
    document.cookie="italkiUserSearchKey"+"="+"memberno"+"="+Memberno+"&speak"+"="+speakVal+"&learn"+"="+learnVal+"&nation"+"="+nationVal+"&maxAge"+"="+maxAgeVal+"&minAge"+"="+minAgeVal+"&gender"+"="+genderVal+"&isAvatar"+"="+(isAvatarVal==true?"1":"0")+"&isChatNow"+"="+(isChatNowVal == true?"1":"0");    
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();